<?php

namespace Service\VenderClient\Hashids;


class Application {

    /**
     * uni
     * @access private
     * @var    string
     */
    private $uni = 'Ly_hashids';


    /**
     * hashids
     * @access private
     * @var    obj
     */
    private $hashids;

    /**
     * instance
     * @access private
     * @var    obj
     */
    private static $instance;

    private function __construct() {
        $this->hashids = new Hashids($this->uni);
    }

    private function __clone() {
    }

    /**
     * @get instance
     * @access   public
     * @return   static
     */
    public static function instance() {
        if (empty(self::$instance)) {
            self::$instance = new static();
        }

        return self::$instance;
    }

    /**
     * @encode
     * @param string $id
     * @access   public
     * @return   string
     */
    public function encode($id = ''): string {
        return $this->hashids->encode($id);
    }

    /**
     * @encode
     * @param string $str
     * @access   public
     * @return   string
     */
    public function decode($str = ''): string {
        $ids = $this->hashids->decode($str);

        return !empty($ids[0]) ? $ids[0] : '';
    }
}